<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\controller;
use think\Loader;

class Announcement extends CrmController
{
    /**
     * announcementList
     */
    public function announcementList()
    {
        $menuname = "Announcement";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];
        $this->assign("priv",$priv);
        // 模板输出
        return $this->fetch('announcementList');
    }


    /**
     * 获取公告列表资料
     * @return [json] [公告数据]
     */
    public function announcementDataList()
    {
        $page = $_REQUEST["page"];
        $limit = $_REQUEST["limit"];
        //需先判断传值是否为空
        $where = "(1 ";
        $where .= empty($_REQUEST["name"])?"":" AND name = '".$_REQUEST["name"]."'";
        $where .= empty($_REQUEST["start_createtime"])?"":" AND createtime > '".$_REQUEST["start_createtime"]."'";
        $where .= empty($_REQUEST["end_createtime"])?"":" AND createtime < '".$_REQUEST["end_createtime"]."'";
        $where .= " )";

        $arrData = Loader::model('Announcement')->getAnnouncementData($where,$page,$limit);
        echo json_encode($arrData);
    }


    /**
     * announcementList
     */
    public function addAnnouncement()
    {
        $menuname = "Announcement";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];
        $this->assign("priv",$priv);
        // 模板输出
        return $this->fetch('addAnnouncement');
    }


    /**
     * 新增病情
     */
    public function insertAnnouncement ()
    {
        $data = $_REQUEST;
        $data['name'] = $_SESSION['user_info']['username'];
        $data['department_id'] = $_SESSION['user_info']['department_id'];
        $data['createtime'] = date('Y-m-d H:i:s');
        // print_r($data);
        Loader::model('Announcement')->insertAnnouncement($data);
    }


}